<?php
require('config.php');

function auth($database,$uid,$codes,$c1,$c2,$c3){
        $db=mysql_connect($database['host'],$database['user'],$database['password']) or die("Could not connect");
        mysql_select_db($database['database']) or die('Could not select database');

        $sql="select * from users where `uid`='$uid'";
//      echo "<br>".$sql."<br>"; 
        $result=mysql_query($sql) or die (mysql_error());
	$row = mysql_fetch_array($result);

//	echo "$c1 $c2 $c3  $codes $row[$c1] $row[$c2] $row[$c3]";
//	echo "<br> ".substr($codes,0,4)." ".substr($codes,4,4)." ".substr($codes,8,4);
	
	if ( (substr($codes,0,4)==$row[$c1]) && (substr($codes,4,4)==$row[$c2]) && (substr($codes,8,4)==$row[$c3])) {
		echo "Success";
	} else {
		echo "Failure";
	}
        mysql_free_result($result);
        mysql_close($db);

}


function getcells () {
	echo rand(1,35)." ";
	echo rand(1,35)." ";
	echo rand(1,35)." ";

}

switch ($_GET['cmd']) {
        case "getcells":
                getcells();
                break;
        case "auth":
                auth($database,$_GET['uid'],$_GET['codes'],$_GET['c1'],$_GET['c2'],$_GET['c3']);
                break;
        default:
                echo "Please use the login page";
}

